package com.ayu.scalalearn.chapter06

/**
  * @Author 徐林玉
  * @Description Test07AbstractClass
  * @Date 2022/7/29 10:44
  * @Version 1.0
  */
object Test07AbstractClass {

  def main(args: Array[String]): Unit = {

    //抽象类
    var p1: PersonTest07 = new WorkerTest07()

    p1.hello()

    println(p1.name)


    println("===============================")
    println("=================anonymousclass")
    //匿名子类

    var p2: PersonTest07 = new PersonTest07 {

      override var name: String = "person guy"

      age = 20

      override def hello(): Unit = {

        println("hello person guy")
      }
    }

    p2.hello()

    println(p2.name)

    println(p2.age)

  }


  abstract class PersonTest07 {

    //没有初始化的用var修饰的可以在子类被override修饰
    var name: String

    //已经初始化的不能
    var age: Int = 18

    def hello(): Unit
  }


  class WorkerTest07 extends PersonTest07 {

    override var name: String = "work guy"

    //编译不通过
    //    override var age: Int = 100

    override def hello(): Unit = {

      println("hello maka baka")
    }
  }

}
